import numpy as np
import scipy
from scipy.fftpack import dst,idst

# def dst2(x):
#     return scipy.fftpack.dst(scipy.fftpack.dst(x.T, norm='ortho').T, norm='ortho')

# # 二维离散余弦反变换
# def idst2(x):
#     return scipy.fftpack.idst(scipy.fftpack.idst(x.T, norm='ortho').T, norm='ortho')

def dst2(x):
    x_dst_rows=dst(x,axis=0,norm='ortho')
    x_dst_2d=dst(x_dst_rows,axis=1,norm='ortho')
    return x_dst_2d

def idst2(x):
    x_idst_rows=idst(x,axis=1,norm='ortho')
    x_idst_2d=idst(x_idst_rows,axis=0,norm='ortho')
    return x_idst_2d

# 生成一个8*8的矩阵
x = np.random.rand(8, 8)
# 将矩阵进行DCT变换
y = dst2(x)
# 将矩阵进行IDCT变换
z = idst2(y)
# 打印结果
print(x)
print(y)
print(z)